<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2017/12/14
 * Time: 9:50
 */

namespace app\api\controller\v1\user;
use app\api\controller\v1\Init;

class User extends Init
{

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('user/user', 'service');
    }
    
    /**
     * 获取用户信息
     * @return \think\Response
     */
    public function info() {
        $user = model('user/user', 'service')->where([
            'token' => $this->params['token']
        ])->cache(true, 3600)->find();
        if(!$user) {
            return $this->response("用户不存在", [], -20002);
        }
        return $this->response('操作成功', $user);
    }

    /**
     * 获取用户列表
     * @return \think\Response
     */
    public function lists() {
        $maps = [];
        $result = $this->model->lists($maps, $this->limit, $this->page);
        return $this->response('操作成功', $result);
    }

    /**
     * 查询贷款中的订单数
     * @return \think\Response
     */
    public function product_order_doing_total() {
        $maps = [
            'uid' => $this->user['id'],
            'status' => 0,
        ];
        $result = \think\Db::name('product_order')
            ->where($maps)
            ->count();
        return $this->response('success', (int) $result);
    }

}